import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home.vue';
import CreatOrder from "@/view/order/CreatOrder";
import LookOrder from "@/view/order/LookOrder";
import OrderSet from "@/view/order/OrderSet";
import Rbasicinfo from "../view/order/creatorder/Rbasicinfo";
import Cost from "../view/order/creatorder/Cost";
import Goods from "../view/order/creatorder/Goods";
import Addrinfo from "../view/order/creatorder/Addrinfo";
import Logistics from "../view/order/creatorder/Logistics";
import Empty from "../components/Empty";
import Business from "../view/order/creatorder/Business";
import NeedUn from "@/view/need/needUn"
import Transport from '@/view/transport/transport'
import DispatchsMa from '@/view/dispatchs/dispatchsMa'
import Vehicle from '@/view/vehicle/vehicle'
import FinancialHome from "../view/finance/FinancialHome";
import receivable from "../view/finance/receivable";

import t_track from "../view/exception/t_track";
import exBrief from "../view/exception/exBrief";
import exDisplay from "../view/exception/exDisplay";
import car from "@/view/carManage/car";
import driver from "@/view/carManage/driver";
import receipt from "@/view/carManage/receipt";
import Login from "../components/Login";

Vue.use(Router)

const routes =[

    {
      path: "/", redirect: "/login"
    },
    // home 主页的 页面的组件 路径规则配置
    {
      path:"/login",
      component: Login
    },
    {
      path: "/home",
      component: Home,
      // home 主页下面的子模块
      children: [
        {
          path: "/",
          component: Empty
        },
        {
          path: "business",
          component: Business
        },
        {
          path: "creatorder",
          component: CreatOrder,
          children: [
            {
              path: "/",
              component: Empty
            },

            {path: "rbasicinfo/:id",
            component: Rbasicinfo
            },
            {
              path: "cost/:id",
              component: Cost
            },
            {
              path: "goods/:id",
              component: Goods
            },
            {
              path: 'addrinfo/:id',
              component: Addrinfo
            },
            {
              path: "logistics/:id",
              component: Logistics
            },
          ]
        },
        {
          path: "lookorder/:id",
          component: LookOrder
        },
        {
          path: "orderset",
          component: OrderSet
        },
        {
          path: "FinancialHome",
          component: FinancialHome
        },
        {
          path: "receivable",
          component: receivable
        },
        {
          path: "needUn",
          component: NeedUn
        },
        {
          path: "transport",
          component: Transport
        },
        {
          path: "dispatchsMa",
          component: DispatchsMa
        },
        {
          path: "vehicle",
          component: Vehicle
        },
        {
          path: "exception/t_track",
          component: t_track
        },
        {
          path: "exception/exBrief",
          component: exBrief
        },
        {
          path: "exception/exDisplay",
          component: exDisplay
        },
        {
          path:"car",
          component:car
        },
        {
          path:"driver",
          component:driver
        },
        {
          path:"receipt",
          component:receipt
        }
      ]
    }
  ]
  const router=new Router({
    mode:'history',
    routes,
})
router.beforeEach((to, from, next) => {

  if (to.path == "/home"){
    //判断是否登陆
    let token = localStorage.getItem("token");
    if (token){
      next()
    }else{
      //跳转到login
      next("/login");
    }
  }else{
    next();
  }
})

  export default router;
